package site.yunnong.atvris.service.domain;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import site.yunnong.atvris.common.enumeration.UserConstant;
import site.yunnong.atvris.dao.domain.User;

import java.util.Arrays;
import java.util.Collection;

/**
 * Spring Security需要的用户详情
 * @author JinghaoZhang
 * @date 2021年-04月-08日
 */
public class UmsUserDetails implements UserDetails {

    private User user;

    public UmsUserDetails(User user) {
        this.user = user;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        // 返回当前用户的权限 todo
        return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
    }

    public User getUser() { return this.user; }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return user.getStatus().equals(UserConstant.ACTIVE_STATUS);
    }
}
